package com.wxn.learncompose.pagers

import androidx.compose.animation.animateContentSize
import androidx.compose.foundation.clickable
import androidx.compose.foundation.indication
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import coil.ImageLoader
import coil.decode.SvgDecoder
import coil.request.ImageRequest
import com.skydoves.landscapist.coil.CoilImage

@Composable fun SvgaImagePager() {
    var enlarge by remember {
        mutableStateOf(false)
    }
    var imgSize = if (enlarge) 320.dp else 80.dp

    Surface {
        Column(
            modifier = Modifier
                .padding(0.dp)
                .fillMaxSize(),
            verticalArrangement = Arrangement.Center,
            horizontalAlignment = Alignment.CenterHorizontally
        ) { 
            
            CoilImage(imageRequest =
                ImageRequest.Builder(LocalContext.current)

                    .data("https://coil-kt.github.io/coil/images/coil_logo_black.svg")
                    .build(),
                modifier = Modifier.padding(0.dp)
                    .size(imgSize)
                    .animateContentSize() { initialValue, targetValue ->  }
                    .clickable(
                        onClick = { enlarge = !enlarge},
                        interactionSource = MutableInteractionSource(),
                        indication = null
                    ),
                contentDescription = "",
                imageLoader = ImageLoader.Builder(LocalContext.current)
                    .components {
                        add(SvgDecoder.Factory())
                    }
                    .build()
                )

        }

    }
}